package util;

import java.util.ArrayList;


public class MethodSig {
	public String _name;
	public ArrayList<CType> _types;
	
	public MethodSig(String methodName, ArrayList<CType> types) {
		_name = methodName;
		_types = types;
	}
	
	public String toString() {
		return _name+_types.toString();
	}
	
	public void agreeWithOtherSig(MethodSig other, TypeAgree rules) throws SemanticException{
		boolean judge = true; //judge if they agree
		int size1 = _types.size(), size2 = other._types.size();
		if(size1 != size2)	
			judge = false;
		//else{
			int minSize = ( (size1>size2)?size2: size1);
			for(int i=0; i< minSize; i++)
			{
				if( !rules.agree(_types.get(i), other._types.get(i)) &&
						!rules.agree(other._types.get(i), _types.get(i))	)
					judge = false;
			}
		//}
		if(judge)
			throw new SemanticException ("method "+_name+_types.toString()+" and "
					+other._name+other._types.toString()+" confilct!");
	}
}
